
kknn_recp = recipe(diagnosis~.,data = train_data) |>
  
  step_smotenc(diagnosis,over_ratio=0.5 ,neighbors=1,seed=123)

kknn_spec = nearest_neighbor() |>
  set_engine("kknn") |>
  set_mode("classification")

kknn_flow = workflow() |>
  add_recipe(kknn_recp) |>
  add_model(kknn_spec)


kknn_fit = fit(kknn_flow,data = train_data)
kknn_predict = augment(kknn_fit,new_data=test_data)

knn_auc = roc_auc(data = kknn_predict,truth = diagnosis,.pred_1,event_level="second")
knn_acc = accuracy(data = kknn_predict,truth = diagnosis,.pred_class)
knn_sens = sensitivity(data=kknn_predict,truth = diagnosis,.pred_class,event_level = "second")
knn_spec = specificity(data=kknn_predict,truth = diagnosis,.pred_class,event_level = "second")
knn_ppv = ppv(data=kknn_predict,truth = diagnosis,.pred_class,event_level = "second")
knn_conf_mat = conf_mat(data=kknn_predict,truth = diagnosis,.pred_class)
knn_f_meas = f_meas(data=kknn_predict,truth = diagnosis,.pred_class,event_level = 'second')

# knn_evaluation_table <- tibble(
#   metric = c("auc", "acc","sens","spec","ppv"),
#   value = c(auc$.estimate, acc$.estimate,sens$.estimate,spec$.estimate,ppv$.estimate)
# )
# 
# knn_evaluation_table

# conf_mat